package com.sghd.fight.module.game.core.model;

import com.sghd.fight.module.game.core.Magic;
import com.sghd.fight.module.game.service.room.Player;
import com.sghd.fight.module.game.service.skill.effect.Effect;
import com.sghd.pojo.fight.game.BuffVo;
import com.sghd.pojo.fight.game.ChessType;
import com.sghd.pojo.fight.game.UnitValue;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author frank
 * @date 2018-10-23 13:48
 * @desc
 **/
public class Buff {
    private int id;
    /** buff来源的技能id*/
    private int skillId;
    private UnitValue type;
    private int value;
    private int time;
    private int coolVal;
    private Date start;
    private Map<String, Object> ctx = new HashMap<>();
    private int level;

    public static Buff valueOf(int buffId, int skillId, UnitValue unitValue, int value, int time, long current,
                               int coolVal, Map<String, Object> ctx, int level) {
        Buff buff = new Buff();
        buff.id = buffId;
        buff.skillId = skillId;
        buff.type = unitValue;
        buff.value = value;
        buff.time = time;
        buff.start = new Date(current);
        buff.coolVal = coolVal;
        buff.ctx = ctx;
        buff.level = level;
        return buff;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public UnitValue getType() {
        return type;
    }

    public void setType(UnitValue type) {
        this.type = type;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public int getTime() {
        return time;
    }

    public void setTime(int time) {
        this.time = time;
    }

    public Date getStart() {
        return start;
    }

    public void setStart(Date start) {
        this.start = start;
    }

    public Map<String, Object> getCtx() {
        return ctx;
    }

    public void setCtx(Map<String, Object> ctx) {
        this.ctx = ctx;
    }

    public int getCoolVal() {
        return coolVal;
    }

    public void setCoolVal(int coolVal) {
        this.coolVal = coolVal;
    }

    public void update(Buff buff) {
        time = buff.time;
        value = buff.value;
        start = buff.start;
    }

    public void decrease(int coolVal) {
        time = time - coolVal;
    }

    //剩余消耗不足
    public boolean isRemove() {
        return coolVal > time;
    }

    public int getSkillId() {
        return skillId;
    }

    public void setSkillId(int skillId) {
        this.skillId = skillId;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public void setMgice(Unit unit) {
        ChessType type = ChessType.valueOf(ctx.get(Effect.MAGIC_TYPE).toString());
        Magic magic = ((Player) unit).getMagic();
        this.time = magic.getMagic(type);
    }

    public BuffVo toVo() {
        return BuffVo.valueOf(id, skillId, type, value, time, coolVal, level);
    }
}
